import { showToast } from "@/components/toast";
import axios from "axios";

const axiosInst = axios.create();
axiosInst.defaults.baseURL = "/";

axiosInst.interceptors.request.use(
  (config) => {
    return config;
  },
  (error) => {
    return Promise.reject(error);
  }
);

// Add a response interceptor
axiosInst.interceptors.response.use(
  (response) => {
    return response.data;
  },
  (error) => {
    showToast(error.response?.data?.message ?? error.message);
    return Promise.reject(error);
  }
);

export const request = axiosInst;
